package fr.xebia.batch;

import java.util.HashMap;
import java.util.Map;

import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParameter;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersInvalidException;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException;
import org.springframework.batch.core.repository.JobRestartException;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Main {

	public static void main(String[] args) throws JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException, JobParametersInvalidException {
		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"/xke-batch-simple.xml", "/data-source-context.xml"}); //"/xke-resourceless.xml"
		context.start();
		
		JobLauncher launcher = (JobLauncher) context.getBean("jobLauncher");
		Job job = (Job) context.getBean("simpleJob");
		
		Map<String, JobParameter> params = new HashMap<String, JobParameter>();
		params.put("inputFile", new JobParameter("classpath:data/flatInput.txt"));
		params.put("outputFile", new JobParameter("C:/temp/test-outputs/test.txt"));
		
		launcher.run(job, new JobParameters(params));
	}
	
}
